﻿#include <boost/json.hpp>
#include <iostream>

namespace json = boost::json;

int show_json() {
  // 1. 解析 JSON 字符串
  json::value jv = json::parse(R"({"name":"Alice","age":25,"skills":["C++","Python"]})");
  std::cout << jv << "\n";

  std::cout << jv << "\n";
  std::string name = jv.at("name").as_string().c_str();
  int age = jv.at("age").as_int64();
  json::array skills = jv.at("skills").as_array();

  std::cout << "Name: " << name << "\nAge: " << age << "\nSkills: ";
  for (const auto &skill: skills) {
    std::cout << skill.as_string().c_str() << " ";
  }
  std::cout << std::endl;

  // 2. 生成 JSON
  json::object obj;
  obj["name"] = "Bob";
  obj["age"] = 30;
  obj["is_student"] = false;
  obj["tags"] = {"developer", "designer"};

  std::string json_str = json::serialize(obj);
  std::cout << "Generated JSON: " << json_str << std::endl;

  return 0;
}